<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function arr(stones) {
      let h = new Array(stones.length).fill(0).map(() => new Map()),
        d = (i, j) => {
          if (h[i].get(j)) return false
          else h[i].set(j, true)
          for (let k = i + 1; k < stones.length; k++) {
            if (stones[k] - stones[i] > j + 1) break
            else if (stones[k] - stones[i] >= j - 1 && d(k, stones[k] - stones[i])) return true
          }
          return i === stones.length - 1
        }
      return d(0, 0)
    };
    console.log(arr([0, 1, 3, 5, 6, 8, 12, 17]));
  </script>
</body>

</html>